package ntd.block.server.impl;

import cn.hutool.core.util.ObjectUtil;
import ntd.block.server.ComServer;
import ntd.block.server.bo.ComServerInBo;
import ntd.block.server.bo.ComServerMsgBo;
import ntd.block.server.listen.ComServerListen;

import java.util.ArrayList;
import java.util.List;

public abstract class ComServerBase implements ComServer {

    /** 监听列表 */
    protected List<ComServerListen> comServerListenList = new ArrayList<>();
    /** 输入参数 */
    protected ComServerInBo comServerInBo;

    @Override
    public void addListen(ComServerListen comServerListen) {
        if (ObjectUtil.isNotNull(comServerListen)) {
            comServerListenList.add(comServerListen);
        }
    }

    protected void onMsg(ComServerMsgBo comServerMsgBo) {
        comServerListenList.forEach(comServerListen -> comServerListen.onMsg(comServerMsgBo));
    }

    protected void onClose(ComServerMsgBo comServerMsgBo) {
        comServerListenList.forEach(comServerListen -> comServerListen.onClose(comServerMsgBo));
    }
}
